<?php
#
#
# Copyright TEDECO, 2009. http://tedeco.fi.upm.es
#
# This file is part of kumenya.
#
# Kumenya is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Kumenya is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
#
#
#
?>
<?php
	Interfaz::ControlarSesion(Contable);

	Interfaz::Recordar();

	$consultaMultiple = FALSE;
	// RANGO DE CUENTAS
	$cuentaFinal = Interfaz::Datos(UidCuentaContableFin);
	if ($cuentaFinal) {
		$consultaMultiple = TRUE;
		$clases = CuentaContable::ConsultarSumasSaldos(Interfaz::Datos());

		if ($clases) {
			$tabla = array();
			$total = array();
			foreach ($clases as $clase) {
				$UidClase = $clase[Uid];
				
				$criterios = array_merge (Interfaz::Datos(), array("UidClase" => $UidClase));
				
				$tabla[$UidClase] = CuentaContable::BalanceSumasSaldos ($criterios);
			
				if (is_array($tabla[$UidClase])) {
					$total[$UidClase] = CuentaContable::TotalBalanceSumasSaldos ($criterios);
					if (is_array($total[$UidClase]))
						continue;
					else {
						if (!Interfaz::HayError())
							Interfaz::Error(_("No se pudo recuperar las cuentas contables"));
						$exito = FALSE;
						break;
					}
				}
				else {
					if (!Interfaz::HayError())
						Interfaz::Error(_("No se pudo recuperar las cuentas contables"));
					$exito = FALSE;
					break;
				}
			}
			include "ResultadoBalanceSumasSaldosExcel.php";
			$exito = TRUE;			
		}
		else {
			if (!Interfaz::HayError())
				Interfaz::Error(_("No se pudo recuperar las cuentas contables"));
			$exito = FALSE;
		}
	}
	else {
		$criterios = array_merge (array(Uid . TablaDeCuentasContables => 
			Interfaz::Datos(UidCuentaContableInicio)), Interfaz::Datos());

		$tabla = CuentaContable::BalanceSumasSaldos ($criterios);	
	
		if (is_array($tabla)) {
			$total = CuentaContable::TotalBalanceSumasSaldos ($criterios);
			
			if (is_array($tabla)) {
				include "ResultadoBalanceMayorExcel.php";
				$exito = TRUE;			
			}
			else
				$exito = FALSE;
		}
		else
			$exito = FALSE;
	}
?>